/**************************************************************************************
* Component of simpleRTJ regression tests.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Created by:
*       RTJ Computing
**************************************************************************************/
public class TestFloat
{

    final static float PI = 3.1415926536F;

    public static void test() throws Exception
    {

       float t = PI;
       if (t != 3.1415926536000001F) throw new Exception("TF1");

       //division test

       t = 4.0F;
       if (t / 3 != (1.0F + 1.0F/3.0F))
            VmTests.printString("TF2: "+(t / 3)+" != "+(1.0F + 1.0F/3.0F)+"\r\n");
        if (t / 5 != 0.8F)
            VmTests.printString("TF3: "+(t / 5)+" != "+(0.8F)+"\r\n");

       //multiplication test
       if (t * 3 != 12) throw new Exception("TF4");

       //modulus test
       if (t % 3.0F != 1.0F)
           VmTests.printString("TF5: "+(t % 3.0F)+" != "+(1.0F)+"\r\n");
       if (t % 4.0F != 0.0F)
           VmTests.printString("TF6: "+(t % 4.0F)+" != "+(0.0F)+"\r\n");
       if (t % 5.0F != 4.0F)
           VmTests.printString("TF7: "+(t % 5.0F)+" != "+(4.0F)+"\r\n");

       //cast test
       t = 4.0F;
       if ((int)t != 4) throw new Exception("TF8");
       if ((byte)t != (byte)4) throw new Exception("TF9");
       t = -1.0F;
       if ((byte)t != (byte)0xff) throw new Exception("TF10");
       if ((short)t != (short)0xffff) throw new Exception("TF11");

       //addition test
       if (t + 1.0F != 0.0F) throw new Exception("TF12");
       if (t + 2.0F != 1.0F) throw new Exception("TF13");

       //subtraction test
       if (t - 1.0F != -2.0F) throw new Exception("TF14");

       //order of evaluation test
       t = 4.0F;
       t = (float)((t + (float)2.0F)/(float)3.0F);
       if (t != 2.0F) throw new Exception("TF15");
       t = (float)(t + t / (float)2.0F);
       if (t != 3.0F) throw new Exception("TF16");
       t = (float)((t + (float)1.0F) * (float)2.0F);
       if (t != 8.0F) throw new Exception("TF17");
       t = (float)(t - t/(float)2.0F);
       if (t != 4.0F) throw new Exception("TF18");

       //assignment
       t = 9.0F;
       t += (t=3.0F);
       if (t != 12.0F) throw new Exception("TF19");
       t = 9.0F;
       t = (float)(t + (t = 3.0F));
       if (t != 12) throw new Exception("TF20");

   }
}
